function optionBar(opt) {
  let option = {
    title: {
      text: opt.title,
      left: '5%',
      top: '2%'
    },
    legend: {
      data: opt.legendData || null,
      top: '3%',
      left: 'center'
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      }
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: [
    {
      name: opt.xUnit,
      nameTextStyle: {
        padding: [30, 0, 0, 0],
      },
      type: 'category',
      data: opt.xData,
      axisTick: {
        alignWithLabel: true,
      }
    }],
    yAxis: [
    {
      type: 'value',
      name: opt.unit,
      alignTicks: true,
      axisLabel: {
        formatter: '{value}'
      }
    }],
    dataZoom: [
    {
      show: false,
      startValue: 0,
      endValue: 31,
    },
    {
      type: 'inside',
    }],
    series: opt.series
  }
  return option
}

function optionLine(opt) {
  let option = {
    title: {
      text: opt.title,
      left: '5%',
      top: '2%'
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          backgroundColor: '#6a7985'
        }
      }
    },
    legend: {
      top: '3%',
      left: 'center'
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: {
      name: opt.xUnit,
      nameTextStyle: {
        padding: [30, 0, 0, 10],
      },
      type: 'category',
      boundaryGap: false,
      data: opt.xData
    },
    yAxis: [
    {
      type: 'value',
      name: opt.unit,
      alignTicks: true,
      axisLabel: {
        formatter: '{value}'
      }
    }],
    dataZoom: [
    {
      show: false,
      startValue: 0,
      endValue: 31,
    },
    {
      type: 'inside',
    }],
    series: opt.series
  }
  return option
}

function optionPie(opt) {
  let option = {
    title: {
      text: opt.title,
      left: '5%',
      top: '2%'
    },
    tooltip: {
      trigger: 'item',
      formatter: `{b}: {c}${opt.unit} ({d}%)`
    },
    legend: {
      type: 'scroll',
      orient: 'vertical',
      right: 10,
      top: 20,
      bottom: 20,
      // data: data.legendData
    },
    graphic: [ //为环形图中间添加文字
      {
        type: "text",
        left: "center",
        top: "47%",
        style: {
          text: opt.topText + opt.unit,
          textAlign: "center",
          fill: "#000",
          fontSize: 18,
        },
      },
      {
        type: "text",
        left: "center",
        top: "54%",
        style: {
          text: opt.bottomText,
          textAlign: "center",
          fill: "#000",
          fontSize: 28,
        },
      },
    ],
    series: [{
      name: opt.name,
      type: 'pie',
      radius: ['40%', '70%'],
      center: ['50%', '50%'],
      avoidLabelOverlap: false,
      label: {
        normal: {
          show: true,
          fontSize: 18,
          position: 'outside',
          formatter: `{b}\n{c} ${opt.unit} 占${opt.bottomText}{d}%`,
        }
      },
      labelLine: {
        normal: {
          show: true,
          length: 30,
          length2: 50,
          lineStyle: {
            type: 'solid',
          }
        }
      },
      data: opt.series
    }]
  }
  return option
}

function noData(text) {
  let option = {
    title: {
      text: text,
      x: 'center',
      y: 'center',
      textStyle: {
        fontSize: 16,
        fontWeight: 'normal',
      }
    }
  }
  return option
}
export default {
  optionBar,
  optionLine,
  optionPie,
  noData
}